﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using House.Server.Dto;
using House.Server.Common;
namespace House.Server.Repository
{
    public class System_PersonalStatusRepostitory : GenericBaseRepository<PersonalStatus>
    {
        public List<PersonalStatus> PersonalSelect(int id,int P_stateStart,int P_stateEnd)
        {
            List<PersonalStatus> list = new List<PersonalStatus>();
            string sql = @"select P_id,P_name,P_phone,P_date,P_state from t_Personal where S_id=@S_id and P_state between @P_stateStart and @P_stateend";
            using (var cnn = DbConnection)
            {
                using (var cmd = cnn.CreateCommand())
                {
                    cmd.CommandText = sql;
                    var p = cmd.CreateParameter();
                    p.ParameterName = "@S_id";
                    p.Value = id;
                    var e = cmd.CreateParameter();
                    e.ParameterName = "@P_stateStart";
                    e.Value = P_stateStart;
                    var q = cmd.CreateParameter();
                    q.ParameterName = "@P_stateend";
                    q.Value = P_stateEnd;
                    cmd.Parameters.Add(p);
                    cmd.Parameters.Add(e);
                    cmd.Parameters.Add(q);
                    var x = cmd.ExecuteReader();
                    try
                    {
                        while (x.Read())
                        {
                            PersonalStatus Personal = new PersonalStatus();
                            Personal.P_id = Convert.ToInt32(x["P_id"]);
                            Personal.P_name = x["P_name"].ToString();
                            Personal.P_phone = x["P_phone"].ToString();
                            Personal.P_state = Convert.ToInt32(x["P_state"]);
                            Personal.P_date = Convert.ToDateTime(x["P_date"]);
                            Personal.P_status = EnumHelper.GetEnumSelectState<EnumInfoState>(Personal.P_state);
                            list.Add(Personal);
                        }
                    }
                    finally
                    {
                        cnn.Close();

                    }
                }
                return list;
            }
        }
    }
}
